import java.io.*;
import java.util.*;

public class A {

    BufferedReader fin;
    PrintWriter fout;

    void openFiles() throws IOException {
        fin = new BufferedReader(new FileReader("A.in"));
        fout = new PrintWriter(new BufferedWriter(new FileWriter("A.out")));
    }

    void closeFiles() throws IOException {
        fin.close();
        fout.close();
    }

    int L, D, N;
    String[] word;
    String[] as;
    
    void input() throws IOException {
        String s = fin.readLine();
        StringTokenizer ss = new StringTokenizer(s);
        L = Integer.parseInt(ss.nextToken());
        D = Integer.parseInt(ss.nextToken());
        N = Integer.parseInt(ss.nextToken());
        word = new String[D];
        for (int i = 0; i < D; i++) word[i] = fin.readLine();
    }

    void interprete(String x)
    {
    	as = new String[L];
        String s = new String("()" + x + "()");
        int open, close = 0, len = 0;
        while (true)
        {
            open = s.indexOf('(', close);
            if (open > close+1)
	        	for (int i = close+1; i < s.length(); i++)
	        	{
	        		if (s.charAt(i) == '(') break;
	        		as[len++] = new Character(s.charAt(i)).toString();
	        	}
            close = s.indexOf(')', open);
            if (close == s.length()-1) break;
            if (close == open+1) continue;
            else as[len++] = s.substring(open+1, close);
        }
    }

    int count()
    {
        int res = 0;
        for (int i = 0; i < D; i++)
        {
            boolean matched = true;
            for (int j = 0; j < L; j++)
            {
                if (as[j].indexOf(word[i].charAt(j)) == -1)
                {
                    matched = false;
                    break;
                }
            }
            if (matched) res++;
        }
        return res;
    }

    void process() throws IOException {
        for (int i = 0; i < N; i++)
        {
            String s = fin.readLine();
            interprete(s);
            fout.println("Case #" + new Integer(i+1).toString() + ": " + count());
        }
    }

    void output() {
    }

    public static void main(String[] args) throws IOException {
        A myProgram = new A();

        myProgram.openFiles();
        myProgram.input();
        myProgram.process();
        myProgram.output();
        myProgram.closeFiles();
    }
}
